const fs = require('fs');
const { promises: fsp } = fs;
const path = require('path');

const svgPath = path.resolve(__dirname, 'src/assets/svg/icon_svg');

// import { ReactComponent as Frame2 } from '../../assets/svg/icon_svg/Frame(1).svg';
// 启动方法 cmd下 node svgimport.js
(async () => {
  const ls = await fsp.readdir(svgPath);
  const ls2 = [];
  for (const name of ls) {
    if (!name.match(/\.svg$/)) {
      return;
    }
    const fullname = path.resolve(svgPath, name);
    const importName = name.replace(/\.svg$/, '');
    const relPath = path.relative(path.resolve(__dirname, 'src/views/layout/'), fullname).replace(/\\/g, '/');
    const str = `import { ReactComponent as ${importName} } from '${relPath}';`;
    ls2.push(importName);
    console.log(str);
  }
  console.log(`const icons = [${ls2.join(', ')}];`);
})();
